package com.xyz.business.service.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import com.xyz.business.bean.Cover;
import com.xyz.business.bean.Enterprise;
import com.xyz.business.bean.Report;
import com.xyz.business.dao.ReportDao;
import com.xyz.business.service.ReportService;
import com.xyz.constant.XYZConstant;
import com.xyz.util.SEQNoHelper;

public class ReportServiceImpl implements ReportService {

	private ReportDao reportDao;

	public void insert(Report report, Enterprise enterprise)
			throws SQLException {

		Cover cover = new Cover();
		cover.setBusscontent(ReportHelper.getBussContentByRptTpe(report
				.getReporttype()));
		// 源公司：广君、广安
		cover.setCompany(ReportHelper.getCompanyByRptTpe(report.getReporttype()));
		// 目的公司：
		cover.setCompanyname(enterprise.getCompanyname());
		String coverid= SEQNoHelper.getSeqNo(XYZConstant.COVER_FLAG);
		cover.setCoverid(coverid);
		cover.setReportno(report.getReportno());
		cover.setReporttype(report.getReporttype());
		cover.setReporttypename(ReportHelper.getRptTyeNameByRptTpe(report
				.getReporttype()));
		cover.setReportyear(report.getReportyear());
		cover.setProjectleader(report.getProjectleader());
		String eid = SEQNoHelper.getSeqNo(XYZConstant.ENTERPRISE_FLAG);
		report.setRid(SEQNoHelper.getSeqNo(XYZConstant.REPORT_FLAG));
		report.setEid(eid);
		report.setCoverid(coverid);
		report.setReporttypename(ReportHelper.getRptTyeNameByRptTpe(report
				.getReporttype()));
		enterprise.setEid(eid);
		report.setIshide(XYZConstant.SHOW_REPORT);
		reportDao.insert(report, enterprise, cover);

	}

	@Override
	public List query(Report report, Enterprise enterprise, int pageNow,
			int pageSize) throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.query(report, enterprise, pageNow, pageSize);
	}

	public ReportDao getReportDao() {
		return reportDao;
	}

	public void setReportDao(ReportDao reportDao) {
		this.reportDao = reportDao;
	}

	@Override
	public int queryReportCount(Report report, Enterprise enterprise)
			throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.queryReportCount(report, enterprise);
	}

	@Override
	public void deleteReport(String rptid) throws SQLException {
		reportDao.deleteReport(rptid);

	}

	@Override
	public void editReport(String rptid) throws SQLException {
		reportDao.editReport(rptid);

	}

	@Override
	public Report queryReportByRptId(String rid) throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.queryReportByRptId(rid);
	}

	@Override
	public void update(Report report, Enterprise enterprise)
			throws SQLException {
		Cover cover = new Cover();
		cover.setBusscontent(ReportHelper.getBussContentByRptTpe(report
				.getReporttype()));
		// 源公司：广君、广安
		cover.setCompany(ReportHelper.getCompanyByRptTpe(report.getReporttype()));
		// 目的公司：
		cover.setCompanyname(enterprise.getCompanyname());
		cover.setReportno(report.getReportno());
		cover.setReporttype(report.getReporttype());
		cover.setReporttypename(ReportHelper.getRptTyeNameByRptTpe(report
				.getReporttype()));
		cover.setReportyear(report.getReportyear());
		cover.setProjectleader(report.getProjectleader());
		cover.setCoverid(report.getCoverid());
		report.setReporttypename(ReportHelper.getRptTyeNameByRptTpe(report
				.getReporttype()));
		report.setIshide(XYZConstant.SHOW_REPORT);
		cover.setCoverid(report.getCoverid());
//		enterprise.setEid(eid)
		reportDao.update(report, enterprise, cover);

	}

	@Override
	public void hide(String rptid) throws SQLException {
		reportDao.hide(rptid);

	}

	@Override
	public List queryCollect(Report report, Enterprise enterprise,
			Date beginTime, Date endTime) throws SQLException {
		// TODO Auto-generated method stub
		return reportDao.queryCollect(report, enterprise,
				beginTime, endTime);
	}

}
